{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Part 4, Topic 3: ChipWhisperer Analyzer CPA Attack (HARDWARE)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "**THIS IS NOT THE COMPLETE TUTORIAL - see file with `(MAIN)` in the name.**\n",
    "\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Sure you don't have hardware, but that doesn't mean we can't have fun! If you check the ChipWhisperer based lab (using hardware), you'll find that the capture loop is as follows:\n",
    "    \n",
    "```python\n",
    "from tqdm.notebook import trange\n",
    "import numpy as np\n",
    "import time\n",
    "\n",
    "ktp = cw.ktp.Basic()\n",
    "trace_array = []\n",
    "textin_array = []\n",
    "\n",
    "\n",
    "proj = cw.create_project(\"Lab 4_3\", overwrite=True)\n",
    "\n",
    "N = 50\n",
    "for i in trange(N, desc='Capturing traces'):\n",
    "    key, text = ktp.next()\n",
    "    trace = cw.capture_trace(scope, target, text, key)\n",
    "    if not trace:\n",
    "        continue\n",
    "    \n",
    "    proj.traces.append(trace)\n",
    "```\n",
    "`cw.capture_trace()` is really just a shorthand for what we've been doing for the other labs, with the only major difference being that it does some extra target specific stuff not typically needed and it returns a Trace object. We're using ChipWhisperer projects here, but more on that in the main tutorial!\n",
    "\n",
    "All we need to do is a project with prerecorded traces:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from cwtraces import sca101_lab_data\n",
    "import chipwhisperer as cw\n",
    "\n",
    "data = sca101_lab_data[\"lab4_3\"]\n",
    "project = data[\"project\"]()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
